package com.guoxin.artconcurrency.chapter8;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author guoxin
 * @date 2019/8/6
 */
public class CyclicBarrierTest2 {
    private static CyclicBarrier cb = new CyclicBarrier(2,new A());

    public static void main(String[] args) throws BrokenBarrierException, InterruptedException {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    cb.await();
                } catch (InterruptedException | BrokenBarrierException e) {
                    e.printStackTrace();
                }
                System.out.println(1);
            }
        }).start();

        cb.await();
        System.out.println(2);
    }

    private static class A implements Runnable{

        @Override
        public void run() {
            System.out.println(3);
        }
    }
}
